(function($){ 
	$.fn.makePlayersList = function(options) {
		// Merge passed options with defaults
	    var opts = $.extend({}, $.fn.makePlayersList.defaults, options);
		
		var context = {options:opts, element:this};
		
		return this.each(function() {
			if (opts.gameName != ""){
				var gameManager = opts.gameManager;
				
				if (gameManager == null){
					gameManager = new TLVIVI.Pacman.GameManager();
				}
				
				gameManager.getGamePlayers(opts.gameName, $.proxy(_onGetDataBack, context));
			}
		 });
	 };
	 
	 function _onGetDataBack(response){
		 var itemTemplate = "<li><img src='' class='listIcon'><span><span><li>";
		 var listContainer = this.element;
		 listContainer.empty();
		 
		 $.each(response, function(index, value){
			 var currPlayer = $(itemTemplate);
			 
			 if (value.Role == 1){
				 $("img", currPlayer).attr("src", "/images/pacman.gif");
			 }
			 else if (value.Role == 2){
				 $("img", currPlayer).attr("src", "/images/monster.gif");
			 }
			 
			 $("span", currPlayer).text(value.Name);
			 
			 if (value.Role == 1 || value.Role == 2){
				 listContainer.append(currPlayer);
			 }
		 });
	 }
	 
	// makeBigAppList plugin default options
	  $.fn.makePlayersList.defaults = {
		gameManager: null,
	    gameName: "",
	    selfId: -1,
	    showSelf: false
	  };

})(jQuery); 


